/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 */
import { BaseEvent, EventAdditional, EventBody, EventHead, MetricEventType } from './base-event.js';

export enum MetadataEventState {
  NEW = 'new',
  IDLE = 'idle',
  BUSY = 'busy',
  CLOSE = 'close',
  BROKEN = 'broken',
}

class MetadataEventAdditional implements EventAdditional {
  category?: string;
  sortIndex?: string;
  label?: string;
  content?: string;
  state: MetadataEventState;

  constructor(state: MetadataEventState) {
    this.state = state;
  }
}

export class MetadataEvent extends BaseEvent {
  additional: MetadataEventAdditional;

  constructor(id: string, name: string, description: string, pid: number, tid: string, state: MetadataEventState) {
    super(new EventHead(id, name, description, MetricEventType.METADATA), new EventBody(pid, tid));
    this.additional = new MetadataEventAdditional(state);
    this.body.startTime = Number(process.hrtime.bigint());
  }

  setCategory(category: string) {
    this.additional.category = category;
  }

  setSortIndex(sortIndex: string) {
    this.additional.sortIndex = sortIndex;
  }

  setLabel(label: string) {
    this.additional.label = label;
  }

  setContent(content: string) {
    this.additional.content = content;
  }
}
